#include <QStyle>

#include "qlsprogressbar.h"

QLsProgressBar::QLsProgressBar(QWidget *parent) :
	QSlider(parent)
{
	setMouseTracking(true);
	setOrientation(Qt::Horizontal);
	installEventFilter(this);
}

/* 事件过滤器 */
bool QLsProgressBar::eventFilter(QObject *watched, QEvent *event)
{
	if(event->type() == QEvent::KeyPress)
	{

	}

	if(event->type() == QEvent::KeyRelease)
	{

	}

	return QSlider::eventFilter(watched, event);
}

/* 鼠标按下事件 */
void QLsProgressBar::mousePressEvent(QMouseEvent *event)
{
	int val = QStyle::sliderValueFromPosition(minimum(), maximum(), event->pos().x(), width());
	setValue(val);

	QSlider::mousePressEvent(event);
}

/* 鼠标释放事件 */
void QLsProgressBar::mouseReleaseEvent(QMouseEvent *event)
{
	emit sigSeek(value() * 1000000);

	QSlider::mouseReleaseEvent(event);
}
